/****************************************************************
 * 查询
 ***************************************************************/

// 根据id查单条数据
const select = {
    user: {
        table: 'user',
        column: 'id, name, nick, image',
        where: {
            id: 1
        }
    }
}

// 返回多条信息，id倒序，取前10条
const select = {
    product: {
        table: 'product',
        column: 'id, name, image, price',
        order: 'id desc',
        limit: '1, 10'
    }
}

// 关键字搜索
const select = {
    product: {
        table: 'product',
        column: 'id, name, image, price',
        where: {
            name: 'like(test)'
        }
    }
}

// 大于等于、小于等于搜索
const select = {
    product: {
        table: 'product',
        column: 'id, name, image, price',
        where: {
            price: 'between(10, 100)'
        }
    }
}

// 使用in语句
const select = {
    product: {
        table: 'product',
        column: 'id, name, image, price',
        where: [
            id: 'in(1, 2, 3, 4, 5)',
            price: 'gte(10)'
        ]
    }
}

// groupby和聚合函数
const select = {
    cash: {
        table: 'cash',
        column: 'id, name, sum(amount) as amount',
        group: 'uid'
    }
}

// 使用session
const select = {
    fav: {
        table: 'fav',
        where: {
            uid: '@(userid)'
        }
    }
}

/****************************************************************
 * 插入
 ***************************************************************/

// 单条插入
const insert = {
    address: {
        table: 'address',
        data: {
            name: '袁涛',
            mobile: '18833245288',
            address: '测试地址'
        }
    }
}

/****************************************************************
 * 更新
 ***************************************************************/

// 单条更新
const update = {
    address: {
        table: 'address',
        data: {
            created: '$(gen.mixed(8))',
            name: '袁涛2',
            mobile: '18833245282',
            address: '测试地址2'
        },
        where: {
            id: 1
        }
    }
}

let arr = [];
for (let item of lists) {
    arr.push({
        table: 'address',
        data: {
            name: item['name'],
            name: item['name'],
            name: item['name']
        },
        where: {
            id: item['id']
        }
    })
}


// 批量更新，通常用于后台列表操作
const update = {
    batch: arr
}

/****************************************************************
 * 删除
 ***************************************************************/

// 单条删除
const delete = {
    address: {
        table: 'address',
        where: {
            id: 1
        }
    }
}

// 批量删除
const delete = {
    address: {
        table: 'address',
        where: {
            id: 'in(1, 2, 3, 4, 5, 6)'
        }
    }
}
